home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10115 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: inforamp.net!ts26-11
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Coding Standards
  5. Date: Wed, 06 Mar 96 05:39:38 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4hj8ek$elu@sam.inforamp.net>
  8. NNTP-Posting-Host: ts26-11.tor.inforamp.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. The company I just started a contract with gave me a set of C++ coding 
  12. standards.  I started reading and couldn't stop laughing.  I can't reproduce 
  13. them word-for-word, because that wouldn't be nice to the authors and might be 
  14. considered a copyright violation or privacy violation, but I'll outline some 
  15. of the points.
  16.  
  17.     -source files should have the extension .cc (not .cpp or .c).
  18.     -header files should have the extension .hh (not .hpp or .h).
  19.     -inline C++ functions should be in a file with the extension .icc (not 
  20. in the primary header).
  21.     -do not use the /* */ comment, except when commenting out entire 
  22. sections of code.  My understanding is that /* */ comments are ANSI comments, 
  23. while // comments are not ANSI.
  24.     -a class which can be instantiated with a "new" must have a copy 
  25. constructor, a destructor and an assignment operator definition.  This will 
  26. extend the project another month. 
  27.     -never use #define instead or const.  What if your concerned about the 
  28. mix between code space and data space.
  29.     -variable are to be declared with the smallest possible scope.
  30.         void c::f() 
  31.         { 
  32.             {
  33.                 int b; 
  34.                 {
  35.                     int a;
  36.                     a=b+c; 
  37.                     b=a+d; 
  38.                 }
  39.                 e=b+d; 
  40.             } 
  41.             f=e+4;    
  42.         }
  43.         this type of optimization could take forever.
  44.     -don't use explicit type conversions.  In other words, don't program 
  45. in windows.  Explicit type conversion is necessary  to convert GDI object 
  46. handles.
  47.     -don't use implicit type conversions implicitly, use them explicitly. 
  48.  Hello!
  49.     -every case statement must be terminated with a break statement.  What 
  50. if you want to step through more then one case statement?
  51.         case ENGINE_NOT_ACTIVE:
  52.             start_engine();
  53.         case ENGINE_ACTIVE_NOT_IN_DRIVE:
  54.             shift_to_drive();
  55.         case ENGINE_ACTIVE_IN DRIVE:
  56.             press_accelerator();
  57.             break;
  58.     -don't use conditional compilation preprocessor directives.  There 
  59. goes cross-platform development.
  60.     -optimize code only when you have a problem.  So we can't optimize 
  61. size in order to anticipate that code size will be a problem.  First we have 
  62. to experience the problem (most likely in the field).
  63.     -access functions are to be inline.  Inline access functions defeat 
  64. the purpose of having access functions.
  65.     -give protected accessors for all data members.  What if we need to 
  66. make the accessor public.  Should we define one protected and one public.
  67.     -++ and -- operations should be on a separate line.
  68.         for (i=0; i<0;
  69.             i++
  70.         );
  71.         Is that better?
  72.     -don't allocate memory and expected someone else will delete it later. 
  73. Can't use OWL, because control classes are automatically deleted for you.
  74.  
  75. Agrivar
  76.